﻿<cfsilent>
	<cfscript>

		sessionAdvice = getProperty("serviceFactory").getBean("sessionAdvice");
		depId = sessionAdvice.getUserProp("teacherDepartment");

		termID = event.getArg("TermID");
		academicYear = event.getArg("AcademicYear");
		academicTerm = event.getArg("AcademicTerm");
		
		sql = "SELECT institute_name 
				FROM t_institute 
				WHERE institute_id = :instituteId ";
		queryObj = new query( datasource=application.dnsSlave );
		queryObj.addParam( name="instituteId", value=depID, cfsqltype="cf_sql_varchar" );
		rs_departmentEntity = queryObj.execute( sql=sql ).getResult(); 
	
		sql = "SELECT 
					t_course.cid, 
					t_course.course_name, 
					t_course.course_credit, 
					t_course.period_week, 
					t_course.period, 
					t_course.period_theory, 
					t_course.period_practice, 
					SUM(CASE WHEN t_plan.cidx = '000' THEN 1 ELSE 0 END) SumCidx, 
					COUNT(*) count, 
					t_course.course_code 
				FROM 
					t_plan 
					INNER JOIN t_course ON t_course.cid = t_plan.cid 
				WHERE 
					t_plan.term_id = :term 
					AND 
					(t_plan.cidx > 'XXX' OR t_plan.cidx < 'XXX') 
					AND 
					t_course.institute_id = :depID 
				GROUP BY 
					t_course.cid, 
					t_course.course_name, 
					t_course.course_credit, 
					t_course.period_week, 
					t_course.period, 
					t_course.period_theory, 
					t_course.period_practice, 
					t_course.course_code 
				HAVING 
					SUM(CASE WHEN t_plan.cidx = '000' THEN 1 ELSE 0 END) > 0 
				ORDER BY 
					t_course.course_name ";
		queryObj = new query( datasource=application.dnsSlave );
		queryObj.addParam( name="term", value=termID, cfsqltype="cf_sql_char" );
		queryObj.addParam( name="depID", value=depID, cfsqltype="cf_sql_varchar" );
		rs_course = queryObj.execute( sql=sql ).getResult(); 

		sql = "SELECT 
					t_course.cid, 
					t_course.course_name, 
					t_course.course_credit, 
					t_course.period_week, 
					t_course.period, 
					t_course.period_theory, 
					t_course.period_practice, 
					SUM(CASE WHEN t_plan.cidx = '000' THEN 1 ELSE 0 END) SumCidx, 
					COUNT(*) count, 
					t_course.course_code 
				FROM 
					t_plan 
					INNER JOIN t_course ON t_course.cid = t_plan.cid 
				WHERE 
					t_plan.term_id = :term 
					AND 
					(t_plan.cidx > 'XXX' OR t_plan.cidx < 'XXX') 
					AND 
					t_course.institute_id = :depID 
				GROUP BY 
					t_course.cid, 
					t_course.course_name, 
					t_course.course_credit, 
					t_course.period_week, 
					t_course.period, 
					t_course.period_theory, 
					t_course.period_practice, 
					t_course.course_code 
				HAVING 
					SUM(CASE WHEN t_plan.cidx = '000' THEN 1 ELSE 0 END) = 0 
				ORDER BY 
					t_course.course_name ";
		queryObj = new query( datasource=application.dnsSlave );
		queryObj.addParam( name="term", value=termID, cfsqltype="cf_sql_char" );
		queryObj.addParam( name="depID", value=depID, cfsqltype="cf_sql_varchar" );
		rs_courseDone = queryObj.execute( sql=sql ).getResult(); 
		
		event.setArg("pageTitle", "教学任务安排 - 计划任务合班");

		currentTab = "labCourse";
		
		if ( rs_course.recordCount eq 0 and rs_courseDone.recordCount gt 0 ) {
			currentTab = "labDone";
		}
		
		targetArgs = structNew();
	
	</cfscript>
</cfsilent>

<div id="headArea">
	<div class="uiHeader uiHeaderWithImage ptm">
		<div class="clearfix uiHeaderTop">
			<div class="uiHeaderActions rfloat">
				<a class="uiButton" href="<cfoutput>#buildURL('DEFAULT_EVENT')#</cfoutput>"><i class="mrs img btnList"></i><span class="uiButtonText">教学任务安排</span></a>
			</div>
			<div>
				<h2 class="uiHeaderTitle">
					<i class="uiHeaderImage img icon16x16 application"></i><cfoutput>#rs_departmentEntity.institute_name# 学期开课目录</cfoutput>
				</h2>
			</div>
		</div>
	</div>
</div>

<div class="UIElement">
	<ul class="senateFirstPage">
		<li>
			<div class="clearfix" id="summary">
				<div class="UItab">
					<div class="tabLables">
						<cfif rs_course.recordCount>
							<span <cfif currentTab eq "labCourse">class="active"</cfif> id="labCourse" tabTarget="Course">需合班</span>
						</cfif>
						<cfif rs_courseDone.recordCount>
							<span <cfif currentTab eq "labDone">class="active"</cfif> id="labDone" tabTarget="Done">已合班</span>
						</cfif>
					
					</div>
				</div>
				<script language="javascript" type="text/javascript">
					//<![CDATA[
					<!--
					$(document).ready(function() {
						
						/* init Tab */
						$("div.tabContent").hide();
						$("div#" + $("div.tabLables span.active").attr("tabTarget")).show();
						
						$("div.tabLables > span").click(function(){
							var $targetID = $(this).attr("tabTarget");
							
							$("div.tabLables span").removeClass("active");
							$(this).addClass("active");
							
							$("div.tabContent").not('[id="' + $targetID + '"]').hide();
							$("div.tabContent#" + $targetID).show();
						});
						
					});
					// -->
					//]]>
				</script>
				
				<cfif rs_course.recordCount>

					<div id="Course" class="tabContent">
					
						<cfif rs_departmentEntity.recordCount>
						
							<cfset passArgs = structNew() />
							<cfset structInsert( passArgs, "DepID", depId, true) />
							<cfset structInsert( passArgs, "TID", termId, true) />
						
							<div class="noticeBlock">
								<div class="operation">
									<a class="uiButton uiButtonSpecial" href="<cfoutput>#buildURL('programPlanDownloadExcel', passArgs)#</cfoutput>"><i class="mrs img btnDownload"></i><span class="uiButtonText">下载教学计划</span></a>
									<a class="uiButton uiButtonSpecial" href="<cfoutput>#buildURL('programTaskDownloadExcel', passArgs)#</cfoutput>"><i class="mrs img btnDownload"></i><span class="uiButtonText">下载教学任务</span></a>
								</div>
								<h3><cfoutput>#rs_departmentEntity.institute_name#</cfoutput></h3>
								<p><span class="img icon16x16 message"></span><em><cfoutput>#academicYear#</cfoutput>-<cfoutput>#academicTerm#</cfoutput></em>学期教学任务, 计划开设课程 <em><cfoutput>#rs_course.recordCount#</cfoutput></em> 门.</p>
								<hr/>
							</div>
						
						</cfif>
					
					
						<cfset structDelete(targetArgs, "DepID", false) />
						<cfset row = 0 />
						<table class="UIEditable">
							<thead>
								<tr>
									<td width="18"></td>
									<td>课程</td>
									<td width="100">课程号</td>
									<td width="25">学分</td>
									<td width="70">排课周学时</td>
									<td width="40">总学时</td>
									<td width="50">理论学时</td>
									<td width="50">实践学时</td>
									<td width="80">任务安排进度</td>
									<td width="18"></td>
								</tr>
							</thead>
							<tbody>
                                <cfloop query="rs_course">
									<cfset row++ />
									<cfset structInsert(targetArgs, "CID", rs_course.cid, true) />
									<tr class="editRows" rowid="<cfoutput>#rs_course.cid#</cfoutput>">
										<td class="index"><cfoutput>#row#</cfoutput></td>
										<td><cfoutput>#rs_course.course_name#</cfoutput></td>
										<td><span class="numeric"><cfoutput>#rs_course.course_code#</cfoutput></span></td>
										<td align="center"><span class="numeric"><cfoutput>#numberFormat(rs_course.course_credit, '_.__')#</cfoutput></span></td>
										<td align="center"><span class="numeric"><cfoutput>#rs_course.period_week#</cfoutput></span></td>
										<td align="center"><span class="numeric"><cfoutput>#rs_course.period#</cfoutput></span></td>
										<td align="center"><span class="numeric"><cfoutput>#rs_course.period_theory#</cfoutput></span></td>
										<td align="center"><span class="numeric"><cfoutput>#rs_course.period_practice#</cfoutput></span></td>
										<td align="center"><span class="numeric"><cfoutput>#(rs_course.count-rs_course.SumCidx)# / #rs_course.count#</cfoutput></span></td>
										<td><a href="<cfoutput>#buildURL('classMergeByCourse', targetArgs)#</cfoutput>" class="stat struct"></a></td>
									</tr>
								</cfloop>
							</tbody>
						</table>

					</div>
				</cfif>
				
				<cfif rs_courseDone.recordCount>

					<div id="Done" class="tabContent">
					
						<cfif rs_departmentEntity.recordCount>
						
							<cfset passArgs = structNew() />
							<cfset structInsert( passArgs, "DepID", depId, true) />
							<cfset structInsert( passArgs, "TID", termId, true) />
						
							<div class="noticeBlock">
								<div class="operation">
									<a class="uiButton uiButtonSpecial" href="<cfoutput>#buildURL('programPlanDownloadExcel', passArgs)#</cfoutput>"><i class="mrs img btnDownload"></i><span class="uiButtonText">下载教学计划</span></a>
									<a class="uiButton uiButtonSpecial" href="<cfoutput>#buildURL('programTaskDownloadExcel', passArgs)#</cfoutput>"><i class="mrs img btnDownload"></i><span class="uiButtonText">下载教学任务</span></a>
								</div>
								<h3><cfoutput>#rs_departmentEntity.institute_name#</cfoutput></h3>
								<p><span class="img icon16x16 message"></span><em><cfoutput>#academicYear#</cfoutput>-<cfoutput>#academicTerm#</cfoutput></em>学期教学任务, 计划开设课程 <em><cfoutput>#rs_course.recordCount#</cfoutput></em> 门.</p>
								<hr/>
							</div>
						
						</cfif>
					
					
						<cfset structDelete(targetArgs, "DepID", false) />
						<cfset row = 0 />
						<table class="UIEditable">
							<thead>
								<tr>
									<td width="18"></td>
									<td>课程</td>
									<td width="100">课程号</td>
									<td width="25">学分</td>
									<td width="70">排课周学时</td>
									<td width="40">总学时</td>
									<td width="50">理论学时</td>
									<td width="50">实践学时</td>
									<td width="80">任务安排进度</td>
									<td width="18"></td>
								</tr>
							</thead>
							<tbody>
                                <cfloop query="rs_courseDone">
									<cfset row++ />
									<cfset structInsert(targetArgs, "CID", rs_courseDone.cid, true) />
									<tr class="editRows" rowid="<cfoutput>#rs_courseDone.cid#</cfoutput>">
										<td class="index"><cfoutput>#row#</cfoutput></td>
										<td><cfoutput>#rs_courseDone.course_name#</cfoutput></td>
										<td><span class="numeric"><cfoutput>#rs_courseDone.course_code#</cfoutput></span></td>
										<td align="center"><span class="numeric"><cfoutput>#numberFormat(rs_courseDone.course_credit, '_.__')#</cfoutput></span></td>
										<td align="center"><span class="numeric"><cfoutput>#rs_courseDone.period_week#</cfoutput></span></td>
										<td align="center"><span class="numeric"><cfoutput>#rs_courseDone.period#</cfoutput></span></td>
										<td align="center"><span class="numeric"><cfoutput>#rs_courseDone.period_theory#</cfoutput></span></td>
										<td align="center"><span class="numeric"><cfoutput>#rs_courseDone.period_practice#</cfoutput></span></td>
										<td align="center"><span class="numeric"><cfoutput>#(rs_courseDone.count-rs_courseDone.SumCidx)# / #rs_courseDone.count#</cfoutput></span></td>
										<td><a href="<cfoutput>#buildURL('classMergeByCourse', targetArgs)#</cfoutput>" class="stat config"></a></td>
									</tr>
								</cfloop>
							</tbody>
						</table>

					</div>
				</cfif>
				
			</div>
		</li>
	</ul>
</div>
